package lk.icta.core.web.action;

import lk.icta.common.AppConstants;
import lk.icta.common.ELandRuntimeException;
import lk.icta.common.ErrorCodes;
import lk.icta.common.dao.DSDivisionDAO;
import lk.icta.common.dao.DistrictDAO;
import lk.icta.common.dao.GNDivisionDAO;
import lk.icta.common.entity.*;
import lk.icta.common.service.DocumentManagementService;
import lk.icta.common.util.GenderUtil;
import lk.icta.common.web.action.BaseAction;
import lk.icta.common.web.action.DocumentUploadAction;
import lk.icta.core.dao.*;
import lk.icta.core.entity.*;
import lk.icta.core.service.*;
import lk.icta.user.entity.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lk.icta.core.service.*;

import java.util.ArrayList;
import java.util.List;

public class LandChildrenAction extends BaseAction {
    private static final Logger logger = LoggerFactory.getLogger(LandAction.class);

    private final LandManagementService landManagementService;
    private long landReferenceNumber;
    private String planNo = null;
    private int lotNo;

    private List<Land> childLandList = new ArrayList<Land>();

    public LandChildrenAction(LandManagementService landManagementService) {
        this.landManagementService = landManagementService;
    }

    public String findChildrenByParentReferenceNumber() {
        logger.debug("find Children By Parent Reference Number {} ", user.getUsername());
        logger.debug("Land Ref number {} ", landReferenceNumber);
        logger.debug("planNo {}", planNo);
        logger.debug("lotNo {}", lotNo);
        try {
            if (landReferenceNumber != 0.0)
                //childLandList = landManagementService.searchChildrenByParentReferenceNumber(user, landReferenceNumber);
                childLandList = landManagementService.searchChildrenByParentLand(user, landReferenceNumber);
            else if ((!"".equals(planNo)) && (lotNo != 0))
                childLandList = landManagementService.searchLandByPlanNoAndLotNo(user, planNo, Integer.toString(lotNo));
            else if (!"".equals(planNo))
                childLandList = landManagementService.searchLandByPlanNo(user, planNo);
        } catch (Exception e) {
            e.printStackTrace();
        }
        logger.debug("child Land Size {}", childLandList.size());
        return SUCCESS;
    }

    public long getLandReferenceNumber() {
        return landReferenceNumber;
    }

    public void setLandReferenceNumber(long landReferenceNumber) {
        this.landReferenceNumber = landReferenceNumber;
    }

    public List<Land> getChildLandList() {
        return childLandList;
    }

    public void setChildLandList(List<Land> childLandList) {
        this.childLandList = childLandList;
    }

    public String getPlanNo() {
        return planNo;
    }

    public void setPlanNo(String planNo) {
        this.planNo = planNo;
    }

    public int getLotNo() {
        return lotNo;
    }

    public void setLotNo(int lotNo) {
        this.lotNo = lotNo;
    }

}
